<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>人员编辑</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<link href="css/select.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/jquery.idTabs.min.js"></script>
<script type="text/javascript" src="js/select-ui.min.js"></script>

</head>
<style>
 img.palaroid {
       position:absolute;
       left:50%;
       top:12%;
       box-shadow:1px 1px 5px #333;
       border:solid #edf6fa;
       border-width:6px 6px 20px 6px;
       width:300px;
       height:250px;
       background:#fff;
     }
     img {
	      width:100%;
     }
.switch {
	width:100px;
	margin:50px 0px 0 100px;
}
.btn_fath {
	margin-top:10px;
	position:relative;
	border-radius:20px;
}
.btn1 {
	float:left;
}
.btn2 {
	float:right;
}
.btnSwitch {
	height:30px;
	width:50px;
	border:none;
	color:#fff;
	line-height:30px;
	font-size:16px;
	text-align:center;
	z-index:1;
}
.move {
	z-index:100;
	width:40px;
	border-radius:20px;
	height:30px;
	position:absolute;
	cursor:pointer;
	border:1px solid #828282;
	background-color:#f1eff0;
	box-shadow:1px 2px 2px 1px #fff inset,0 0 5px 1px #999;
}
.on .move {
	left:60px;
}
.on.btn_fath {
	background-color:#44b549;
	height:30px
}
.off.btn_fath {
	background-color:#828282;
	height:30px
}

</style>
<body>
	<!-- 隐藏域 -->
	<input type="hidden" class="personCode" />
	<input type=hidden class="vcardBase" />
	<div class="place">
    <span>位置：</span>
    <ul class="placeul">
    <li><a href="index.html">首页</a></li>
    <li><a href="personnel_list.html" target="rightFrame">人员管理</a></li>
    <li><a href="#" id="text"></a></li>
    </ul>
    </div>
    
    <div class="formbody">
    
    <div class="formtitle"><span>基本信息</span></div>
    
    <ul class="forminfo">
    <li><label>姓名<b>*</b></label><input type="text" class="dfinput pname" /></li>
    <li><label>邮箱<b>*</b></label><input type="text" class="dfinput email" /><i>例：abc@xx.xxx</i></li>
	<li><label>电话<b>*</b></label><input type="text" class="dfinput phoneNumber" /><i>手机号码或区号+座机号</i></li>
	<li><label>身份证号码<b>*</b></label><input type="text" class="dfinput cardNum" onblur="valueToAge()"/></li>
	<li><label>年龄</label><input type="text" class="dfinput age" /></li>
	<li><label>性别<b>*</b></label><cite><input name="sex" type="radio" value="1" checked="checked" />男&nbsp;&nbsp;&nbsp;&nbsp;<input name="sex" type="radio" value="2" />女</cite></li>
	<li><label>所属单位</label><input type="text" class="dfinput company" /><i>所在单位或社区</i></li>
	<li><label>地址</label><input type="text" class="dfinput address" /><i></i></li>
	<li><label>个人主页</label><input type="text" class="dfinput website" /></li>
    <li><label>个人简介</label><textarea class="textinput title"></textarea></li>
    <li><label id="istext">是否生成名片</label>
    	<div class="switch">
    <div class="btn_fath clearfix off" onclick="toogle(this)">
        <div class="move" data-state="off"></div>
        <div class="btnSwitch btn1">是</div>
        <div class="btnSwitch btn2 ">否</div>
    </div>
</div>
    </li>
    <li><label>&nbsp;</label><input  type="button" class="btn" value="提交"/></li>    

    </ul>
			
	<img class="palaroid" style="display: none"/>

    </div>

    <div class="tip">
    	<div class="tiptop"><span>提示信息</span><a></a></div>
        
      <div class="tipinfo">
        <span><img src="images/ticon.png" /></span>
        <div class="tipright">
        <p>是否确认提交信息 ？</p>
        <cite>如果是请点击确定按钮 ，否则请点取消。</cite>
        </div>
        </div>
        
        <div class="tipbtn">
        <input name="" type="button"  class="sure" value="确定" />&nbsp;
        <input name="" type="button"  class="cancel" value="取消" />
        </div>
    
    </div>  
  <script type="text/javascript">
  
  //是否生成名片
  function toogle(th) {
	    var ele = $(th).children(".move");
	    if (ele.attr("data-state") == "on") {//关闭回掉
	        ele.animate({
	            left: "0"
	        }, 300, function() {
	            ele.attr("data-state", "off");
	        });
	        $(th).removeClass("on").addClass("off");
	    } else if (ele.attr("data-state") == "off") {//开启回掉
	  	    		    	
	    	var name=$('.pname').val();
	    	var address=$('.address').val();
	    	var company=$('.company').val();
	    	var phonenumber=$('.phoneNumber').val();
	    	var title=$('.title').val();
	    	var email=$('.email').val();
	    	var website=$('.website').val();
	    	var jsonVcard={"personName":name,"personAddress":address,"personCompany":company,
	    				   "personPhonenumber":phonenumber,"personTitle":title,"personEmail":email,
	    				   "personWebsite":website
	    					};
	    	$.ajax({
	    		url:"/Servicing/qr/getQrVCard",
	    		data:jsonVcard,
	    		dataType:"text",
	    		type:"POST",
	    		success:function(result){
	    			$('.vcardBase').val(result);
	    			$('.palaroid').css("display","");
	    			$('.palaroid').attr("src","data:image/png;base64,"+result);
	    		}	
	    	})
	        ele.animate({
	            left: '60px'
	        }, 300, function() {
	            $(this).attr("data-state", "on");
	        });
	        $(th).removeClass("off").addClass("on");
	    }
	}
$(document).ready(function(e) {
	var hid=location.search.substring(5);
	var title="添加";
	if(hid!=null&&hid!=""){
		title="修改";
		var jsonstr={"id":hid};
		$.ajax({
			url:"/Servicing/person/findPersonInfo",
			data:jsonstr,
			dataType:"json",
			type:"POST",
			success:function(result){
				console.log(result);
				$.each(result,function(key,value){
					$('.palaroid').css("display","");
					$('.personCode').val(value.personCode);					
					$('.pname').val(value.personName);
					$('.email').val(value.personEmail);
					$("input[name='sex'][value="+value.personSex+"]").attr("checked",true); 
					$('.phoneNumber').val(value.personPhonenumber);
					$('.cardNum').val(value.personCard);
					$('.age').val(value.personAge);
					$('.company').val(value.personCompany);
					$('.address').val(value.personAddress);
					$('.website').val(value.personWebsite);
					$('.title').val(value.personTitle);
					$('.vcardBase').val(value.personVcard);
					$('.palaroid').attr("src","data:image/png;base64,"+value.personVcard);
					$('#istext').text("是否重新生成");
				})
			}
		})
	}
	$('#text').text(title);
    $(".select").uedSelect({
		width : 167		  
	});
	 
	$(".btn").click(function(){
		$(".tip").fadeIn(200);
	});
	 $(".tiptop a").click(function(){
		$(".tip").fadeOut(200);
	});


	 $(".sure").click(function(){			
		 //确认回调
		if(hid!=null&&hid!=""){
			 var code=$('.personCode').val();
			 var name=$('.pname').val();	//姓名
			 var email=$('.email').val();			//邮箱
			 var phoneNumber=$(".phoneNumber").val();	//电话
			 var cardNum=$(".cardNum").val();	//身份证号码
			 var age=$('.age').val();	//年龄
			 var sex=$("input[name='sex']:checked").val();	//性别
			 var company=$('.company').val();	//所属单位
			 var address=$('.address').val();	//地址
			 var website=$('.website').val();	//个人主页
			 var title=$('.title').val();	//个人简介
			 var vcardBase=$('.vcardBase').val();	//个人名片二维码 base64
			 var jsonStr1={"personCode":code,"personName":name,"personEmail":email,
				 	  "personPhonenumber":phoneNumber,"personCard":cardNum,"personAge":age,"personSex":sex,
				 	  "personCompany":company,"personAddress":address,"personWebsite":website,
				 	  "personTitle":title,"personVcard":vcardBase};
			 $.ajax({
				 url:"/Servicing/person/updatePerson",
				 data:jsonStr1,
				 dataType:"text",
				 type:"POST",
				 success:function(result){
					 if(result="success"){
						 alert("人员修改成功！");
						 $(".tip").fadeOut(100);
					 }else{
						 alert("人员修改失败！");
						 $(".tip").fadeOut(100);
					 }
				 }
			 })
		}else{
			 var code="P"+getTime();
			 var name=$('.pname').val();	//姓名
			 var email=$('.email').val();			//邮箱
			 var phoneNumber=$(".phoneNumber").val();	//电话
			 var cardNum=$(".cardNum").val();	//身份证号码
			 var age=$('.age').val();	//年龄
			 var sex=$("input[name='sex']:checked").val();	//性别
			 var company=$('.company').val();	//所属单位
			 var address=$('.address').val();	//地址
			 var website=$('.website').val();	//个人主页
			 var title=$('.title').val();	//个人简介
			 var vcardBase=$('.vcardBase').val();	//个人名片二维码 base64
			 var jsonStr2={"personCode":code,"personName":name,"personEmail":email,
					 	  "personPhonenumber":phoneNumber,"personCard":cardNum,"personAge":age,"personSex":sex,
					 	  "personCompany":company,"personAddress":address,"personWebsite":website,
					 	  "personTitle":title,"personVcard":vcardBase};
			 $.ajax({
				 url:"/Servicing/person/insertPerson",
				 data:jsonStr2,
				 dataType:"text",
				 type:"POST",
				 success:function(result){
					 if(result="success"){
						 alert("人员添加成功！");
						 $(".tip").fadeOut(100);
					 }else{
						 alert("人员添加失败！");
						 $(".tip").fadeOut(100);
					 }
				 }
			 })
		}

	
		 
	});
	//关闭提示信息
	$(".cancel").click(function(){
		  $(".tip").fadeOut(100);
	});
});
function valueToAge(){	
 	var cardNum=$('.cardNum').val();
	if (cardNum == null || cardNum == "") {
		alert("身份证号码不能为空！");
	} else if (cardNum.length != 18) {
		alert("请检查身份证号码格式是否有误！");
	} else {
		var myDate = new Date();
		var month = myDate.getMonth() + 1;
		var day = myDate.getDate();

		var age = myDate.getFullYear() - cardNum.substring(6, 10) - 1;
		if (cardNum.substring(10, 12) < month
				|| cardNum.substring(10, 12) == month
				&& cardNum.substring(12, 14) <= day) {
			age++;
		}
		$(".age").val(age); 
	}
}
//获取当前系统时间 
function getTime(){
    var mydate = new Date();
    var str = mydate.getHours();
    str+=mydate.getMinutes() ;
    str+=mydate.getSeconds() ;
    return str; 
}
</script> 	
</body>
</html>
